package com.tool.bloomFilter;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import org.springframework.stereotype.Component;

/**
 * @author 酒徒
 * @Version 1.0
 * @data 2025/4/14 11:04
 */
@Component
public class GuavaBloomFilter {
    private static final int EXPECTED_ELEMENTS = 100;
    private static final double FALSE_POSITIVE_PROBABILITY = 0.01;
    private BloomFilter<Integer> bloomFilter;

    public GuavaBloomFilter() {
        bloomFilter = BloomFilter.create(
                Funnels.integerFunnel(),
                EXPECTED_ELEMENTS,
                FALSE_POSITIVE_PROBABILITY
        );
    }

    public void addElement(Integer element) {
        bloomFilter.put(element);
    }

    public boolean mightContain(Integer element) {
        return bloomFilter.mightContain(element);
    }
}
